<template>
  <div class="adminqianming">
    <admin_top></admin_top>
    <div style="padding:0 20px 20px 20px" class="t_btn_box">
        <el-input style="width:180px" size="small" v-model="all.name" placeholder="请输入店铺名称"></el-input>
        <el-button @click="search" size="small" type="danger">搜索</el-button>
    </div>
    <div style="padding: 0 20px;">
      <el-table :data="tableData" style="text-align: center;" align="center" border :loading="loading">
        <el-table-column label="总金额">
          <template slot-scope="scope">
            <span>{{ scope.row.total }}</span>
          </template>
        </el-table-column>
        <el-table-column label="本单可退金额">
          <template slot-scope="scope">
            <span>{{ scope.row.total - scope.row.balance }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <span>{{ scope.row.status_label }}</span>
          </template>
        </el-table-column>


        <el-table-column label="时间">
          <template slot-scope="scope">
            <span>{{ scope.row.created_at }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">

            <el-button type="text" @click="tuikuan(scope.row)">退款</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="fenye" style="padding: 20px; text-align: right;">
        <el-pagination background layout="prev, pager, next" @current-change="fanye" :page-size="all.page_size"
          :total="total"></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import admin_top from './top.vue';
  import axios from 'axios'
  export default {
    components: {
      admin_top
    },
    name: 'adminqianming',
    data() {
      return {
        all: {
          name:'',
          page_size: 200,
          page: 1,
        },
        tableData: "",
        total: "",
        loading: true,
        //搜索店铺名称

      }
    },
    watch: {

    },
    computed: {

    },
    created() {
      this.getlist()
    },
    methods: {
      tuikuan: function(item) {
        this.$prompt('请输入退款金额', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                }).then(({ value }) => {
                  axios.post('/api/plan-market/admin/shop/refund', {
                      id: item.id,
                      refund_amount: value
                    })
                    .then(response => {
                      if (response.data.msg.code == 0) {
                        this.$message.success('已退款');
                        this.getlist()
                      } else {
                        this.$message.error(response.data.msg.info);
                      }
                    })
                })


      },
      //翻页
      fanye: function(page) {
        this.loading = true
        this.all.page = page
        this.getlist()
      },
      //获取全部
      getlist: function() {
        var that = this
        axios.get('/api/plan-market/admin/shop/recharges', {
            params: this.all
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              this.tableData = response.data.data.data
              this.total = response.data.data.total
              this.loading = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //搜索
      search() {
            //获取列表
            this.getlist()
        },

    },

  }
</script>

<style scoped>
  .adminqianming {
    background: #EAEAEA;
    min-height: 100vh;
    padding: 0px;
  }
  .t_btn_box{
    display: flex;
    justify-content: flex-end;
  }
</style>
